package de.LooLo;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

/**
 * Items for mapview
 * @author Kevin Seppelt, Lukas Siedel 
 *
 */
public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {

	private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
	private Context context;
	private int state;

	public CustomItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}

	public CustomItemizedOverlay(Drawable defaultMarker, Context context,
			int state) {
		this(defaultMarker);
		this.context = context;
		this.state = state;
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mapOverlays.get(i);
	}

	@Override
	public int size() {
		return mapOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		
		OverlayItem item = mapOverlays.get(index);
		
		if (state == 1) {
			Toast.makeText(context, "You are here", Toast.LENGTH_SHORT).show();
			return true;
		}

		if (state == 2 || state == 3) {
			
			Intent intent = new Intent(context, DetailActivity.class);
			intent.putExtra("loo_id", Integer.parseInt(item.getTitle()));
			context.startActivity(intent);
			
			return true;
		}

		return false;

	}

	public void addOverlay(OverlayItem overlay) {
		mapOverlays.add(overlay);
		this.populate();
	}

}